package com.xywl.escort.utils;

import android.text.TextUtils;

import java.io.File;
import java.util.regex.Pattern;

public class FileUtil {

    /**
     * 获取文件扩展名
     * @param file
     * @return
     */
    public static String getExtensionName (File file) {
        String name = file.getName();
        int index = name.lastIndexOf(".");
        if (index > 0) {
            return name.substring(index + 1, name.length());
        }
        return "";
    }

    public static boolean isImageFormat (File file) {
        String extName = getExtensionName(file);
        if (!TextUtils.isEmpty(extName)) {
            if (Pattern.compile("^(jpg|jpeg|png)$").matcher(extName).matches()) {
                return true;
            }
        }
        return false;
    }
}
